class Game < ActiveRecord::Base
	has_many :positions, :dependent => true
	
	def create_side(position, color, pawn_row, major_piece_row)
		("a".."h").each {|file| position.send("#{file}#{pawn_row}=", "#{color}p")}
		["r", "n", "b", "q", "k", "b", "n", "r"].each_with_index {|piece, index| position.send("#{(?a +index).chr}#{major_piece_row}=", "#{color}#{piece}")}
	end

	def after_create
		position = Position.new
		create_side(position, "w", 2, 1)
		create_side(position, "b", 7, 8)
		position.turn = "w"
		position.game = self
		position.save
	end
	
end
